﻿using PelitaProduksi.Controller;
using PelitaProduksi.Helper;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PelitaProduksi.View
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
            txtUser.Focus();
        }

        private void login()
        {
            //Login
            string user, pass;
            user = txtUser.Text;
            pass = txtPass.Text;
            // CHECK ON CREDENTIAL
            bool ok = true;
            user = "spv";
            //ok = LoginHelper.Instance.CheckLogin(user, pass);
            if (ok)
            {
                // IF LOGIN OK
                Main m = new Main(this, user);
                this.Visible = false;
                m.Visible = true;
                m.BringToFront();
                m.Focus();
            }
            else
            {
                // ERROR LOGIN
                MessageBox.Show("Username atau Password salah", "Error Login", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtUser.Clear();
                txtPass.Clear();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            login();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            // Setting
            Setting s = new Setting();
            s.Visible = true;
            s.Focus();
            s.BringToFront();
        }

        private void txtPass_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                login();
                e.Handled = true;
            }
        }

        private void txtUser_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                login();
                e.Handled = true;
            }
        }

    }
}
